class person:
    def __init__(self,name,age,weight):
        self.name=name
        self.age=age
        self.weight=weight
    def run(self):
        self.weight-=0.5
        print(f'{self.name}跑步了，体重减少了0.5斤此时体重为{self.weight}')
    def eat(self):
        self.weight+=0.3
        print(f'{self.name}吃大餐，体重增加了1公斤此时体重为{self.weight}')
    def __str__(self):
        return f'{self.name}现在体重是{self.weight}'
#对象
elephant=person('大象',21,110)
elephant.eat()
elephant.run()
print(elephant)
print("-"*100)
class HouseItem:
    def __init__(self,name,area):
        self.name=name
        self.area=area
    def __str__(self):
        return f'{self.name}的面积为{self.area}'
class House:
    def __init__(self,house_type,area):
        self.house_type=house_type
        self.area=area
        self.free_area=area#剩余面积
        self.house_item=[]#家具列表
    def add_item(self,item:HouseItem):#类名是注解的作用
        #如果剩余面积大于家具面具则可以放入
        if self.free_area>=item.area:
            self.house_item.append(item.name)
            self.free_area-=item.area

        else:
            print('空间不足')
    def __str__(self):
        return (("户型：%s\n,总面积：%.2f\n,剩余：%.2f\n,家具：%s")
                %(self.house_type,self.area,self.free_area,
                  self.house_item))

#创建家具
bed=HouseItem('席梦思',4)
chest=HouseItem('衣服',2)
house=House('三室一厅',60)
house.add_item(bed)
print(house)
print("*"*100)
class woman:
    def __init__(self,name,age):
        '''方法名字不可以改变，用于初始换对象属性的'''
        self.name=name
        self.__age=age#私有属性只有在类内部才能访问
    def __secret(self):#私有方法
        print(self.__age)#在内部访问私有属性
    def boyfriend(self):
        self.__secret()


if __name__=='__main__':
    #构造对象
    xiaoming=woman('小明',18)
    xiaoming.boyfriend()

class animal:
    def eat(self):
        print('eat')
    def drink(self):
        print('drink')
    def run(self):
        print('run')
    def sleep(self):
        print('sleep')
class Dog(animal):
    def bark(self):
        print('bark')

class xiaotianquan(Dog):
    def fly(self):
        print('fly')
    def bark(self):
        super().bark()#调用父类
        print("像神一样叫")


if __name__=='__main__':
    wangcai=Dog()
    wangcai.eat()
    wangcai.drink()
    xiaotianquan=xiaotianquan()
    xiaotianquan.bark()